package cn.liziguo.tank.vector;

import com.almasb.fxgl.core.math.Vec2;
import com.almasb.fxgl.entity.Entity;

/**
 * @author Liziguo
 * @date 2022/7/8 16:11
 */
public final class Vector2 {
    private Vector2() {
    }

    public static final Vec2 ZERO = new Vec2(0, 0);
    public static final Vec2 UP = new Vec2(0, -1);
    public static final Vec2 DOWN = new Vec2(0, 1);
    public static final Vec2 LEFT = new Vec2(-1, 0);
    public static final Vec2 RIGHT = new Vec2(1, 0);

    /**
     * 根据vector 校正entity的面朝向
     *
     * @param vector 向量
     * @param entity 实体
     */
    public static void setRotation(Vec2 vector, Entity entity) {
        // 此处为==判断 请传入Vector2里定义的常量
        if (vector == Vector2.UP) {
            entity.setRotation(0);
        } else if (vector == Vector2.DOWN) {
            entity.setRotation(180);
        } else if (vector == Vector2.LEFT) {
            entity.setRotation(-90);
        } else if (vector == Vector2.RIGHT) {
            entity.setRotation(90);
        } else {
            throw new RuntimeException("设置方向失败");
        }
    }

}
